#!/bin/bash

ZKPATH=~/code/zookeeper-3.3.5
MONGOPATH=~/code/mongodb-linux-x86_64-static-legacy-2.2.2

# start zookeeper
cd $ZKPATH
sh bin/zkServer.sh start &> /dev/null
netstat -ntlp 2>&1 | grep 2181 &> /dev/null
if [[ $? -eq 0 ]]; then
    echo 'Apache Zookeeper start OK.'
else
    echo 'Apache Zookeeper start FAILED.'   
    exit
fi
cd -

# start mongodb
cd $MONGOPATH
nohup ./bin/mongod --dbpath ./data &> ./mongodb.log &
netstat -ntlp 2>&1 | grep 27017 &> /dev/null
if [[ $? -eq 0 ]]; then
    echo 'Mongodb start OK.'
else
    echo 'Mongodb start FAILED.'
    exit
fi

# All done
echo ''
echo '==== Prepare Env OK ===='
